<?php
/**
 * 百度随机图片
 */
error_reporting(0);
$sub = ver('sub', 1, 1);
$class = ver('class');

function image($class, $sub = '', $rand = 1000) {
	$i = rand(0, $rand);
	$url = "http://image.baidu.com/data/imgs?pn=0&rn=18&col=%E5%A3%81%E7%BA%B8&tag={$class}&tag3={$sub}&width=0&height=0&ic={$i}&ie=utf8&oe=utf-8&image_id=&fr=channel&p=channel&from=1&app=img.browse.channel.wallpaper&t=0.08688646721576121";
	$content = file_get_contents($url);
	$Json = json_decode($content, 1);
    $Num = count($Json['imgs']);
    $Arrnum = rand(0,$Num-2);
    return $Json['imgs'][$Arrnum]['imageUrl'];
}

if (empty($sub) or !isset($sub)) {
  $sub = '';
}

$img = image($class, $sub);
$suff = ltrim(strrchr($img, '.'), '.');
header("content-type:image/{$suff}");
echo file_get_contents($img);
//header(Location.":{$img}");
